/**
 * @file:          Chopper.h
 * @brief:         
 * @details:       
 * @author:        wjh
 * @date created:  2023.07.13
 * @version:       1.0.0
 * @par copyright (c):
 *   
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.07.13,14:38:11
 */


#ifndef _CHOPPER_H_
#define _CHOPPER_H_

/* Include Files **************************************************************/
#include "Datatype.h"

/* Macro Definition ***********************************************************/
#define SQRT_2 0.7071067811865475244008F
/* Data Type Define ***********************************************************/
enum ChopperModeEnum
{
    ChopperMode_FastDecay = 0,
    ChopperMode_SlowDecay = 1,
    ChopperMode_HybridDecay = 2,
    ChopperMode_AdaptiveHybridDecay = 3,
};

enum SVPWMModeEnum
{
    SVPWMMode_2phase4vector = 0,
    SVPWMMode_2phase8vector = 1,
    SVPWMMode_3phase6vector = 2,
};

enum SVPWM_2Phase8Vector_SectionN
{
    SVPWM_2Phase8Vector_Section1 = 0,
    SVPWM_2Phase8Vector_Section2 = 2,
    SVPWM_2Phase8Vector_Section3 = 10,
    SVPWM_2Phase8Vector_Section4 = 11,
    SVPWM_2Phase8Vector_Section5 = 15,
    SVPWM_2Phase8Vector_Section6 = 13,
    SVPWM_2Phase8Vector_Section7 = 5,
    SVPWM_2Phase8Vector_Section8 = 4,
};

typedef struct Chopper
{
    /* public data */

    uint16 param_chopper_mode;
    uint16 param_svpwm_mode;
    uint16 param_offset_pwm_en;
    float param_base_pwm;
    float param_offset_pwm;
    float param_hybrid_decay_ratio; /* Slow decay time : fast decay time */


    float in_Ualpha;
    float in_Ubeta;
    float out_Duty_A1;
    float out_Duty_A2;
    float out_Duty_B1;
    float out_Duty_B2;
    float offset_pwm;
    float slow_decay_duty_Aphase;
    float fast_decay_duty_Aphase;
    float slow_decay_duty_Bphase;
    float fast_decay_duty_Bphase;

    uint16_t A;
    uint16_t B;
    uint16_t C;
    uint16_t D;
    uint16_t N;
    float X;
    float Y;
    float Z;
    float W;
    float duty_x;
    float duty_y;
    float duty_0;
    float duty_a;
    float duty_b;
    float duty_c;
    float duty_cm1;
    float duty_cm2;
    float duty_cm3;
    float duty_cm4;

    /* private data */
    
    /* public method */
    void (*Init)(struct Chopper *self);
    void (*OverModulation)(struct Chopper *self);
    void (*SVPWM)(struct Chopper *self);
    void (*Output)(struct Chopper *self);
    
    /* private method */
    
}Chopper;
/* Variable Declare ***********************************************************/

/* Function Declare ***********************************************************/
void Chopper_Init(struct Chopper *self);
void Chopper_OverModulation(struct Chopper *self);
void Chopper_SVPWM_2phase4vector(struct Chopper *self);
void Chopper_SVPWM_2phase8vector(struct Chopper *self);
void Chopper_SVPWM_3phase6vector(struct Chopper *self);
void Chopper_Output_FastDecay(struct Chopper *self);
void Chopper_Output_SlowDecay(struct Chopper *self);
void Chopper_Output_HybridDecay(struct Chopper *self);
void Chopper_Output_AdaptiveHybridDecay(struct Chopper *self);


#endif